<%@page import="java.text.SimpleDateFormat"%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*"%>
<%@ page language="java" import="java.text.SimpleDateFormat"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	String loginAccount = (String)session.getAttribute("loginAccount");
	//String lastLoginTime = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format((String)session.getAttribute("loginTime"));
	String lastLoginTime= (String)session.getAttribute("loginTime");

 %>
<style type="text/css">
	.tenant_switch_select_div{
		border-right: 1px solid #dee5e8;
		float: right;
		height: 60px;
		box-sizing: content-box !important;
	}
	.manager_back{
		background: rgba(0, 0, 0, 0) url("${ctx}/static/threadui/img/manager_go_back.png") no-repeat scroll center center;
		float: right;
		height: 50px;
		width: 30px;
		margin-top: -43px;
		padding-right: 10px;
		margin-right: 6px;
		box-sizing: content-box !important;
	}
	.cinema_exit{
		padding-left: 25px;
	}
	.tenant_switch_select_div .select_showbox{
		background-color: #fdfdfd;
		border-radius: 2px;
		box-sizing: content-box !important;
	}
	
	.tenant_switch_select_div .select_box{
		margin-right: 40px;
		margin-top: 10px !important;
		box-sizing: content-box !important;
	}
	.tenant_switch_select_div .select_option{
		border-radius: 2px;
		top: 31px;
		box-sizing: content-box !important;
	}
	.modal-backdrop {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 999;
		background-color: #000;
		opacity:0.4;
	}
	
	.fade {
		box-sizing: border-box;
	}
	
	.advance_tip_d {
		z-index: 2000;
	}
	.advance_tip_d{
		background-color: unset;
	}
</style>
<body>
	<div class="cinema_maipinquan">运营平台</div>
	<div style="background-image: url('${ctx}/static/threadui/img/manager_go_back.png');width:20px;height:20px;">
	<a id="logOutBut" href="javascript:if(confirm('确认要退出吗？'))window.location='${ctx}/sys/logout'" class="cinema_icon"></a>
	</div>
	
	<div class="cinema_logo"></div>
	<div class="cinema_exit">
		<p> 您好!<span class="cinema_name"><%=loginAccount%></span></p>
		<h1>上次登录时间:<span><%=lastLoginTime%></span></h1>
	</div>
	<!-- 等待遮罩 -->
	<div class="advance_tip hidden advance_tip_d" style="margin-top: 5%; width: 400px; left: 39%;">
		<div class="movie_center" style="width: 150px; height: 90px;">
			<div id="loader" style="margin-top: 45px; width: 150px; height: 90px"></div>
		</div>
	</div>
	
	<div class="tenant_switch_select_div">
		
	</div>
</body>
<script type="text/javascript">
	var now_tenant_id = $(".tenant_switch_select").val();
	$(".tenant_switch_select").find("option").on("click",function(){
		var switch_tenant = $(this).val();
		if(now_tenant_id==switch_tenant){
			return false;
		}
		$('#loader').shCircleLoader();
		shade();
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async: false,
	        url: '${ctx}/sysUserInfo/switchTenant',
	        data: {tenantId:switch_tenant},
	        success: function (data) {
	        	if(data!=undefined&&data.status=="0"){
					location.replace(location);
	        	}else{
	        		alert(data.error);
	        	}
        		clear();
        		$('#loader').shCircleLoader('destroy');
	        },
	        error: function(data) {
        		alert(data.data);
        		clear();
        		$('#loader').shCircleLoader('destroy');
	        }
	    });
		now_tenant_id = switch_tenant;
	});
	//遮罩
	function shade() {
		$(".advance_tip_d").removeClass("hidden");
		$("body").append("<div id='fadeDiv' class='modal-backdrop fade in'></div>");
	}
	function clear() {
		$(".advance_tip_d").addClass("hidden");
		$("#fadeDiv").remove();
	}
	$("#switch_back_but").click(function(){
		if(confirm("是否退出租户切换。")){
			$('#loader').shCircleLoader();
			shade();
			$.ajax({
		        type: "POST",
		        dataType: "json",
		        async: false,
		        url: '${ctx}/sysUserInfo/switchTenantBack',
		        data: {},
		        success: function (data) {
		        	if(data!=undefined&&data.status=="0"){
		        		$("#logOutBut").click();
						location.replace(location);
		        	}else{
		        		alert(data.error);
		        		window.location.href = "${ctx}/logout";
		        	}
	        		clear();
	        		$('#loader').shCircleLoader('destroy');
	        		return false;
		        },
		        error: function(data) {
	        		alert(data.data);
	        		clear();
	        		$('#loader').shCircleLoader('destroy');
	        		$("#logOutBut").click();
		        }
		    });
    		clear();
    		$('#loader').shCircleLoader('destroy');
    		return false;
		}
	});
</script>